package com.cn.crmsystem.controller.approveController;
import com.cn.crmsystem.pojo.Login;
import com.cn.crmsystem.pojo.ResultJson;
import com.cn.crmsystem.pojo.Task;
import com.cn.crmsystem.pojo.User;
import com.cn.crmsystem.service.approveService.BranchService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
@Controller
@Api(value = "下属任务api",tags = "下属任务API")
public class BranchController {
	@Autowired
	BranchService branchService;
	//下属任务条件查询
	@RequestMapping(value = "/selectBranchCondition",name="下属任务条件查询",method = RequestMethod.POST)
	@ApiOperation(value = "下属任务条件查询",notes = "条件查询",httpMethod = "POST", response = String.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "userid",value = "用户id",paramType = "query",dataType = "Integer",required = false),
			@ApiImplicitParam(name = "createid",value = "领导id",paramType = "query",dataType = "Integer",required = false),
			@ApiImplicitParam(name = "role",value = "用户角色",paramType = "query",dataType = "Integer",required = false),
			@ApiImplicitParam(name = "endDate",value = "截至时间",paramType = "query",dataType = "Integer",required = false)
	})
	@ResponseBody
	public ResultJson selectBranchCondition(@RequestParam(name = "userid") Integer userid,
										@RequestParam(name = "createid") Integer createid,
										@RequestParam(name = "role") Integer role,
										@RequestParam(name = "endDate") java.util.Date endDate){
		ResultJson resultJson=new ResultJson();
		Login login=new Login();
		List<User> list=new ArrayList<>();
		list=branchService.selecteAllauser(userid);
		Task task=new Task();
		task.setCreate_Id(createid);
		task.setRole(role);
		task.setEnd_Date(endDate);
		for(int i=0;i<list.size();i++){
			login.setId(list.get(i).getId());
			resultJson=branchService.SelectBranchConditionAll(task,login);
		}
		return resultJson;
	}
	//下属任务全查
	@RequestMapping(value = "/SelectBranchAll",name = "下属任务全查",method = RequestMethod.POST)
	@ApiOperation(value = "下属任务全查",notes = "查询",httpMethod = "POST", response = String.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "userid",value = "用户id",paramType = "query",dataType = "Integer",required = false)
	})
	@ResponseBody
	public ResultJson SelectBranchAll(@RequestParam(name = "userid") Integer userid){
		ResultJson resultJson=new ResultJson();
		List<User> list=new ArrayList<>();
		list=branchService.selecteAllauser(userid);
		resultJson=branchService.SelectBranchAll(list);
		return resultJson;
	}
	//查询参与者
	@RequestMapping(value = "/SelectBranchjoinner",name = "查询参与者",method = RequestMethod.POST)
	@ApiOperation(value = "查询参与者",notes = "查询",httpMethod = "POST", response = String.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "userid",value = "用户id",paramType = "query",dataType = "Integer",required = false)
	})
	@ResponseBody
	public ResultJson SelectBranchjoinner(@RequestParam(name = "userid") Integer userid){
		ResultJson resultJson=new ResultJson();
		List<User> list=new ArrayList<>();
		list=branchService.selecteAllauser(userid);
		resultJson.getSuccess("成功",list);
		return resultJson;
	}
	//任务修改
	@RequestMapping(value = "/UpdateBranchTask",name = "任务修改",method = RequestMethod.POST)
	@ApiOperation(value = "任务修改",notes = "更新",httpMethod = "POST", response = String.class)
	@ResponseBody
	public ResultJson UpdateBranchTask(@RequestBody
								   @ApiParam(name ="新建任务",value = "增加") Task task){
		ResultJson resultJson=new ResultJson();
		resultJson=branchService.UpdateBranchTask(task);
		return resultJson;
	}
	//任务删除
	@RequestMapping(value = "/DeleteBranchTask",name = "任务删除",method = RequestMethod.POST)
	@ApiOperation(value = "任务删除",notes = "更改deleteid",httpMethod = "POST", response = String.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "taskId",value = "任务id",paramType = "query",dataType = "Integer",required = false)
	})
	@ResponseBody
	public ResultJson DeleteBranchTask(@RequestParam(name = "taskId") Integer taskId){
		ResultJson resultJson=new ResultJson();
		resultJson.getSuccess("成功",200);
		return resultJson;
	}
	//任务新增
	@RequestMapping(value = "/InsertBranchTask",name = "任务新增",method = RequestMethod.POST)
	@ApiOperation(value = "任务新增",notes = "插入",httpMethod = "POST", response = String.class)
	@ResponseBody
	public ResultJson InsertBranchTask(@RequestBody
								   @ApiParam(name ="新建任务",value = "增加") Task task){
		ResultJson resultJson=new ResultJson();
		resultJson.getSuccess("成功",200);
		return resultJson;
	}
}
